//
//  WYReplyController.m
//  Boss
//
//  Created by admin on 2018/7/2.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYReplyController.h"
#import "WYReplyCell.h"
#import "WYReplayModel.h"
#import "WYBusinessDetailController.h"
@interface WYReplyController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@end

@implementation WYReplyController
-(NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self loadData];
    [self setNoDataViweWithTitle:@"您还没任何回复哦～" img:[UIImage imageNamed:@"粉丝"]];
    // Do any additional setup after loading the view.
}

-(void)loadData
{
    WEAKSELF
    [WYHttpServer getUserReplySucessBlock:^(BOOL success, id response, NSString *errorMessage) {
        if (success) {
            [weakSelf.dataArray addObjectsFromArray:[WYReplayModel getReplayModelFromJson:response[@"result"][@"detail"]]];
            [weakSelf.tableView reloadData];
            if (weakSelf.dataArray.count) {
                [weakSelf hiddenNoDataView];
            }else{
                [weakSelf showNoDataView];
            }
            
        }
        
        
        
    }];
    
    
    
}

-(void)setupUI
{
    self.navigationItem.title = @"我的回复";
    
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"WYReplyCell" bundle:nil] forCellReuseIdentifier:@"WYReplyCell"];
    self.tableView.estimatedRowHeight = 70;
    self.tableView.tableFooterView = [[UIView alloc]init];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WYReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYReplyCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"WYFoodCell" owner:nil options:nil].firstObject;
    }
    
    WYReplayModel *model = self.dataArray[indexPath.row];
    [cell setModel:model];
    
    [cell setSelectionStyle:(UITableViewCellSelectionStyleNone)];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WYBusinessDetailController *bvc = [[WYBusinessDetailController alloc]init];
    WYReplayModel *model = self.dataArray[indexPath.row];
    bvc.urlString = model.businessId;
    [self.navigationController pushViewController:bvc animated:YES];
    
}



- (UITableView *)tableView
{
    if (_tableView == nil) {
        CGRect frame = CGRectMake(0, self.navHeight, kScreenWidth, kScreenHeight-self.navHeight);
        _tableView = [[UITableView alloc] initWithFrame:frame
                                                  style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
     //   [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
    }
    return _tableView;
}
@end
